package com.ft.controller;

import com.ft.model.enums.OrderStatusChangeEventEnum;
import com.ft.service.OrderStateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author: zhangjianghua
 * @Date: 2018-10-10 13:44
 */
@Controller
@RequestMapping("/orders")
public class OrderController {
    @Autowired
    private OrderStateService orderStateService;

    /**
     * 通过触发一个事件，改变一个订单的状态
     * @param orderId
     * @param event
     * @return
     */
    @PostMapping("/{orderId}")
    public ResponseEntity processOrderState(@PathVariable("orderId") Long orderId, @RequestParam("event") OrderStatusChangeEventEnum event) {
        Boolean result = orderStateService.change(orderId, event);
        return new ResponseEntity(result, HttpStatus.OK);
    }

}
